package camo.utils
{
	import camo.controllers.helpers.ClassHelper;
	
	public class ClassFinderUtility
	{
		
		private static var __instance : ClassFinderUtility;
		private var _classHelper:ClassHelper;
		
		/**
		 * Use ClassFinderUtility.instance to access method on the utility.
		 * @return instance: Reference to the class
		 */
		public static function get instance() : ClassFinderUtility {
			if(ClassFinderUtility.__instance == null) {
				ClassFinderUtility.__instance = new ClassFinderUtility(new SingletonEnforcer());
			}
			return ClassFinderUtility.__instance;
		}
		
		/**
		 * 
		 * @param enforcer
		 * 
		 */		
		public function ClassFinderUtility(enforcer : SingletonEnforcer) {
			if (enforcer == null) {
				throw new Error("Error: Cannot instantiate ClassFinderUtility directly, use ClassFinderUtility.instance instead of new.");
			}else {
				_classHelper = new ClassHelper("camo.views.components");
			}
		}
		
		/**
		 * 
		 * @param className
		 * @param pathToClass
		 * @return 
		 * 
		 */		
		public function getClass(className : String, pathToClass : String = null) : Class {
			return _classHelper.getClass(className, pathToClass);
		}
		
		/**
		 * 
		 * @param className
		 * @return 
		 * 
		 */		
		public function getBasePackage(className : String) : String {
			return _classHelper.getBasePackage(className);
		}
		
		/**
		 * 
		 * @param className
		 * @return 
		 * 
		 */		
		public function splitClassName(className : String) : Array {
			return _classHelper.splitClassName(className);
		}

	}
}

internal class SingletonEnforcer {
}